Crate openraft_macros

source ·
Expand description

Supporting utils for Openraft.

§add_async_trait

#[add_async_trait] adds Send bounds to an async trait.

§Example

#[openraft_macros::add_async_trait]
trait MyTrait {
    async fn my_method(&self) -> Result<(), String>;
}

The above code will be transformed into:

trait MyTrait {
    fn my_method(&self) -> impl Future<Output=Result<(), String>> + Send;
}

§since

#[since(version = "1.0.0")] adds a doc line /// Since: 1.0.0.

§Example

/// Foo function
#[since(version = "1.0.0")]
fn foo() {}

The above code will be transformed into:

/// Foo function
///
/// Since: 1.0.0
fn foo() {}

§expand a template

expand!() renders a template with arguments multiple times.

§Example:

expand!(KEYED, // ignore duplicate by `K`
        (K, T, V) => {let K: T = V;},
        (a, u64, 1),
        (a, u32, 2), // duplicate `a` will be ignored
        (c, Vec<u8>, vec![1,2])
);

The above code will be transformed into:

let a: u64 = 1;
let c: Vec<u8> = vec![1, 2];

Macros§

  • Render a template with arguments multiple times.

Attribute Macros§

  • This proc macro attribute optionally adds Send bounds to a trait.
  • Add a Since line of doc, such as /// Since: 1.0.0.